package be.jhd.appserver.weblogic.command;

import java.util.ArrayList;
import java.util.List;

public class CommandBuilder {
	
	private boolean builded = false;
	private final List<String> commandList = new ArrayList<String>();
	
	public CommandBuilder add(String key) {
		isNotYetBuilded();
		commandList.add(String.format("-%s", key));
		return this;
	}
	
	public CommandBuilder add(String key, String value) {
		add(key);
		commandList.add(String.format("%s", value));
		return this;
	}

	private void isNotYetBuilded() {
		if(builded){
			throw new RuntimeException("Object alredy builded!");
		}
	}

	public String[] build() {
		builded = true;
		return commandList.toArray(new String[commandList.size()]);
	}
	
	public String toString(){
		return commandList.toString();
	}

}
